package com.lanou3g.ptp.filecontrol.service.Impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.lanou3g.ptp.filecontrol.service.UploadService;
import org.apache.commons.io.IOUtils;
import org.springframework.boot.system.ApplicationHome;

import java.io.*;

@Service
public class UploadServiceImpl implements UploadService {

    @Override
    public String fileUpload(InputStream inputStream,String path) throws IOException {

        ApplicationHome applicationHome = new ApplicationHome(getClass());
        File source = applicationHome.getSource();
//        String parent = source.getParent();


        String fileName = path.substring(path.lastIndexOf("/") + 1);
        String filePath = path.replace("/" + fileName,"");


        String parent = "/Users/mylovelyziwei/IdeaProjects/ptp/ptp-filecontrol-service/target";
        String newPath = parent + "/FileContorl/resource" + path;

        File file1 = new File(parent + "/FileContorl/resource" +filePath);

        if(file1.mkdirs()) {

            FileOutputStream outputStream = new FileOutputStream(newPath);

            IOUtils.copy(inputStream, outputStream);
        }

        return null;
    }
}
